<template>
  <div class="execution">
    <basic-container>
      <avue-crud
        ref="crud"
        :page="page"
        :data="tableData"
        :permission="permissionList"
        :table-loading="tableLoading"
        :option="tableOption"
        :upload-preview="uploadPreview"
        @on-load="getList"
        @row-save="handleSave"
        @row-del="rowDel"
        @row-update="handleUpdate"
        @search-change="searchChange"
      >
        <template slot-scope="scope" slot="menuLeft">
        </template>
      </avue-crud>
    </basic-container>
  </div>
</template>

<script>
import {
  addObj,
  delObj,
  fetchList,
  putObj
} from "@/api/subway/swsttickettestitem";
import {
  tableOption,
} from "@/const/crud/subway/swsttickettestitem";
import { mapGetters } from "vuex";

export default {
  name: "Sttickettestitem",
  data() {
    return {
      searchForm: {},
      form: {},
      fileList: [],
      enabledUploadBtn: true,
      uploadBtnIcon: "el-icon-upload2",
      tableData: [],
      page: {
        total: 0, // 总页数
        currentPage: 1, // 当前页数
        pageSize: 20, // 每页显示多少条
      },
      tableLoading: false,
      tableOption: tableOption,
      TestVisDialog: false,
    };
  },
  created() {},
  mounted() {},
  computed: {
    ...mapGetters(["permissions"]),
    permissionList() {
      return {}
    },
  },
  methods: {
    Test(row) {
      this.form = row;
      this.TestVisDialog = true;
    },
    edit() {
      putObj(this.form).then(() => {
        this.$message({
          showClose: true,
          message: "修改成功",
          type: "success",
        });
        this.getList(this.page);
         this.TestVisDialog = false;
        done();
      });
    },
    getList(page, params) {
      this.tableLoading = true;
      return fetchList(
        Object.assign(
          {
            current: page.currentPage,
            size: page.pageSize,
          },
          params,
          this.searchForm
        )
      ).then((response) => {
        this.tableData = response.data.data.records;
        this.page.total = response.data.data.total;
        this.tableLoading = false;
      });
    },
    handleBeforeOpen(done) {
      this.form.type = this.dictType;
      this.form.dictId = this.dictId;
      done();
    },
    handleEdit(row, index) {
      this.$refs.crud.rowEdit(row, index);
    },
    handleDel(row, index) {
      this.$refs.crud.rowDel(row, index);
    },
    rowDel: function (row) {
      var _this = this;
      this.$confirm("是否确认删除该数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return delObj(row);
        })
        .then(() => {
          this.getList(this.page);
          _this.$message({
            showClose: true,
            message: "删除成功",
            type: "success",
          });
        })
        .catch(function () {});
    },
    handleUpdate: function (row, index, done) {
      putObj(row).then(() => {
        this.$message({
          showClose: true,
          message: "修改成功",
          type: "success",
        });
        this.getList(this.page);
        done();
      });
    },
    handleCancel: function (row, index) {
      row.checkStatus = 0;
      var _this = this;
      this.$confirm("是否确认取消通知该数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return putObj(row);
        })
        .then(() => {
          this.getList(this.page);
          _this.$message({
            showClose: true,
            message: "取消通知成功",
            type: "success",
          });
        })
        .catch(function () {});
    },
    operBtn(row) {
      if (row.isReceive == "否") {
        return false;
      } else {
        return true;
      }
    },
    auditBtn(row) {
      if (row.isReceive == "否") {
        return true;
      } else {
        return false;
      }
    },
    resolveBtn(row) {
      if (row.isReceive == "是") {
        return false;
      } else {
        return true;
      }
    },
    handleAdd: function () {
      this.$refs.crud.rowAdd();
    },
    handleSave: function (row, done) {
      row.checkStatus = 0;
      addObj(row).then(() => {
        this.$message({
          showClose: true,
          message: "添加成功",
          type: "success",
        });
        this.getList(this.page);
        done();
      });
    },
    searchChange(form, done) {
      this.searchForm = form;
      this.getList(this.page, form).then(() => {
        done();
      });
    },
    handleAudit(row, index) {
      this.form.nowOpenId = row.id;
      this.dialogAuditVisible = true;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>
